package com.my.study.controller;

import com.my.study.entity.vo.ResponseVO;
import com.my.study.handler.RoleSendCallbackHandler;
import com.my.study.producer.service.RocketMqSendService;
import com.my.study.service.RoleUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role")
@Slf4j
public class RoleController {

    @Autowired
    private RoleUserService roleUserService;
    @Autowired
    private RocketMqSendService rocketMqSendService;
    @Autowired
    private RoleSendCallbackHandler roleSendCallbackHandler;

    @GetMapping("/query")
    public ResponseVO queryRole(@RequestParam(name = "roleId") String roleId){
        return ResponseVO.success(roleUserService.queryRole(roleId));
    }

    @GetMapping("/remove")
    public ResponseVO removeRoleById(@RequestParam(name = "roleId") String roleId){
        roleUserService.removeRoleById(roleId);
        rocketMqSendService.syncSend("role_producer_topic",roleId);
        return ResponseVO.success();
    }

    @GetMapping("/remove2")
    public ResponseVO removeRoleById2(@RequestParam(name = "roleId") String roleId){
        roleUserService.removeRoleById(roleId);
        rocketMqSendService.asyncSend("role_producer_topic",roleId,roleSendCallbackHandler);
        return ResponseVO.success();
    }

    @GetMapping("/remove3")
    public ResponseVO removeRoleById3(@RequestParam(name = "roleId") String roleId){
        roleUserService.removeRoleById(roleId);
        rocketMqSendService.asyncSendHandlerErrorData("role_producer_topic",roleId);
        return ResponseVO.success();
    }
}
